<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/8/14
  Time: 19:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <script src="js/jquery/jquery.min.js"></script>
    <script src="js/jquery.validation/1.14.0/jquery.validate.min.js"></script>
    <script src="js/jquery.validation/1.14.0/messages_zh.min.js"></script>
    <style>
        input.error {
            border: 1px solid #E6594E;
        }
    </style>
</head>
<body>
<div class="container">
    <form id="addNewsForm">
        <br/>
        <div class="form-group">
            <label for="title">标题：</label>
            <input type="text" class="form-control" id="title" name="title" value="${news.title}" placeholder="输入标题">
        </div>
        <div class="form-group">
            <label for="contact">内容：</label>
            <input type="text" class="form-control" id="contact" name="contact" value="${news.contact}" placeholder="输入内容">
        </div>
        <div class="form-group">
            <button type="button" id="updateBtn" class="btn btn-success">确认修改</button>
            <button type="button" id="cancelBtn" class="btn btn-default">取消</button>
        </div>
    </form>
</div>
<script>
     var updateNews = function () {
          if(!check().form()){
              return;
          }
          $.ajax({
               type:'POST',
              dataType:'json',
              url:'/updateNews',
              data:{
                   id:${news.id},
                  title:$("#title").val(),
                contact:$("#contact").val()
              },
         success: function () {
             $("#cancelBtn").click();
         }


          });
     }
     $("#updateBtn").click(function () {
         updateNews();
     });


$("#cancelBtn").click(function () {
    var index = parent.layer.getFrameIndex(window.name);
    parent.getNewsPageList();
    parent.layer.close(index);
});
           function  check() {
               return $("#addNewsForm").validate({
                   rules:{
                       title:{
                           required:true
                       },
                       contact:{
                           required:true
                       }
                   },
                   messages:{
                       title:{
                           required:""
                       },
                       contact:{
                           required:""
                       }
                   }
               });
           }


</script>
</body>
</html>
